package com.namecard.namecardapi.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.namecard.namecardapi.entity.AccountInfo;
import com.namecard.namecardapi.entity.vo.UserAccountVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author wzx
 * @since 2023-07-03
 */

@Mapper
@DS("slave")
public interface AccountInfoMapper extends BaseMapper<AccountInfo> {

    /**
     * 查询用户积分余额数据
     * @param userId 用户id
     * @return 返回余额
     */
    BigDecimal selectPointBalance(@Param("userId") String userId);


    /**
     * 修改用户积分余额数据
     * @param userId 当前用户的id
     * @param newPoint 支付后的积分余额
     * @return 更新结果
     */
    int updatePoint(@Param("userId") String userId, @Param("newPoint") BigDecimal newPoint);

    /**
     创建用户账号
     */
    int createAccount(@Param("userId") String userId);


    /**
     获取余额数据
     */

    UserAccountVO selectBalanceData(@Param("userId") String userId);


    @Select("SELECT pi_balance,point_balance,available_balance,frozen_balance FROM account_info WHERE uid = #{userId}")
    AccountInfo selectOneAccount(@Param("userId") String userId);

    @Select("SELECT id, uid, point_balance,available_balance,frozen_balance,del_flag,pi_balance FROM account_info WHERE uid = #{uid}")
    AccountInfo selectAccountInfoByUid(String uid);
}
